package testing;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.Scanner;
import se.kth.id2212.bankjdbc.*;

public class BankTest {

	/**
	 * @param args
	 */
	private static String bankName = "NordBanken";
	
	public static void main(String[] args) throws RemoteException {
		Scanner in = new Scanner(System.in);
		System.out.println("Name?");
		String name = in.nextLine();
		Bank bank = null;
		Account acc = null;
		try {
			bank  = (Bank)Naming.lookup(bankName);
			
			
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NotBoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			acc = bank.newAccount(name);
			
		} catch (RemoteException ea)
		{
			System.out.println("asd");
			/*if (ea.getCause() instanceof Rejected)
			{
				System.out.println("Account already exist");

				acc = bank.getAccount(name);
			} */
				
		} catch (RejectedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		System.out.println("Balance " + acc.getBalance() );
		System.out.println("Depositing 100");
		try {
			acc.deposit(100);
		} catch (RejectedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("New balance " + acc.getBalance());
		

	}

}
